package com.example.demo.event;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class Event {
    //@Bean("applicationEventMulticaster")
    @Bean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
    ApplicationEventMulticaster createApplicationEvent(ThreadPoolTaskExecutor taskExecutor){
        SimpleApplicationEventMulticaster simple=new SimpleApplicationEventMulticaster();
        simple.setTaskExecutor(taskExecutor);
        return simple;
    }
    @Bean
    public CommandLineRunner BeanRunner(ApplicationContext tx){
        return args -> {
            System.out.println("所有的Bean:");
            String[] strings=tx.getBeanDefinitionNames();
            for(String s:strings)
                System.out.println(s);
        };
    }
}
